﻿using MediatR;
using Traceability.Commont.Domains.ScratchTheFat;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
namespace U.Enterprise.Api.Applications.SalesWeighingEXE
{
    public class SalesWeighingCreateHandler : IRequestHandler<SalesWeighingCreateCommond, Resqults>
    {

        private readonly IBateRepository<SalesWeighing> _SalesWeighing;

        public SalesWeighingCreateHandler(IBateRepository<SalesWeighing> salesWeighing
            )
        {
            _SalesWeighing = salesWeighing;
        }

        public async Task<Resqults> Handle(SalesWeighingCreateCommond request, CancellationToken cancellationToken)
        {
           

            var list=new Resqults() { Code = 0 };


            var query = new SalesWeighing()
            {
                SalesWeighingID = request.SalesWeighingID,
                ScaleId=request.ScaleId,
                State= request.State,
                Adjust=request.Adjust,
                ApproachNo=request.ApproachNo,
                ClientID=request.ClientID,
                AverageWeight=request.AverageWeight,
                NetWeight=request.NetWeight,
                ProductCode=request.ProductCode,
                ProductNo=request.ProductNo,
                Remark=request.Remark,
                RepositoryID=request.RepositoryID,
                Tare=request.Tare,
                WeigheTime=request.WeigheTime,
                WeightNum=request.WeightNum,
            };


            var result=await _SalesWeighing.Add(query);

            if(result!=null)
            {

                list.Code = 1;
}



            return list;
        }
    }
}
